home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
026a
/
miltime.zip
/
MILTIME.UDF
Wrap
Text File
|
1991-07-04
|
2KB
|
44 lines
From UserId Jcoc on the ATBBS. 07/01/91.
Taken from message traffic on the ATBBS.
Do your own testing. No guarantees are made.
MilTime() UDF converts an H:MM AM/PM time string to HH:MM:SS 24 hour time.
FUNCTION MilTime
PARAMETER pass_time
PRIVATE pass_time,t_str,rvalue,hr_loc,hr_time
t_str=TRIM(LOWER(pass_time)) && convert A to a and P to p
DO CASE
CASE AT('a',t_str)<>0 && is 12-hour time and AM
rvalue=SUBSTR(t_str,1,AT('a',t_str)-1)
IF val(rvalue)<10.and.AT('0',rvalue)<>1 && add leading zero if necessary
rvalue='0'+rvalue && add a leading zero
ENDIF
* check for 12:00 AM to 12:59 AM. should be 00:nn in 24 hr time
IF rvalue='12'
rvalue='00'+SUBSTR(rvalue,3)
ENDIF
CASE AT('p',t_str)<>0 && is 12-hour time and PM
rvalue=SUBSTR(t_str,1,AT('p',t_str)-1)
hr_loc=AT(':',t_str)
IF hr_loc<>0 && if a valid time string
hr_time=VAL(SUBS(t_str,1,hr_loc-1))
* check for 01:00 PM to 11:59 PM. add 12 hours for 24 hr time
IF hr_time<12
hr_time=hr_time+12
ENDIF
hr_time=LTRIM(STR(hr_time))
rvalue=hr_time+SUBSTR(rvalue,hr_loc)
ELSE
?? chr(7) && invalid time was passed
rvalue='**:**'
ENDIF
OTHERWISE && if already 24-hour time
rvalue=t_str
* add leading zero if necessary
IF VAL(rvalue)<10.and.AT('0',rvalue)<>1
rvalue='0'+rvalue
ENDIF
ENDCASE
RETURN(TRIM(rvalue))